{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import pandas\n",
    "food_info = pandas.read_csv(\"food_info.csv\")\n",
    "#print(type(food_info))\n",
    "print food_info.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#first_rows = food_info.head()\n",
    "#print first_rows\n",
    "#print(food_info.head(3))\n",
    "#print food_info.columns\n",
    "#print food_info.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#pandas uses zero-indexing\n",
    "#Series object representing the row at index 0.\n",
    "#print food_info.loc[0]\n",
    "\n",
    "# Series object representing the seventh row.\n",
    "#food_info.loc[6]\n",
    "\n",
    "# Will throw an error: \"KeyError: 'the label [8620] is not in the [index]'\"\n",
    "#food_info.loc[8620]\n",
    "#The object dtype is equivalent to a string in Python"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#object - For string values\n",
    "#int - For integer values\n",
    "#float - For float values\n",
    "#datetime - For time values\n",
    "#bool - For Boolean values\n",
    "#print(food_info.dtypes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Returns a DataFrame containing the rows at indexes 3, 4, 5, and 6.\n",
    "#food_info.loc[3:6]\n",
    "\n",
    "# Returns a DataFrame containing the rows at indexes 2, 5, and 10. Either of the following approaches will work.\n",
    "# Method 1\n",
    "#two_five_ten = [2,5,10] \n",
    "#food_info.loc[two_five_ten]\n",
    "\n",
    "# Method 2\n",
    "#food_info.loc[[2,5,10]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Series object representing the \"NDB_No\" column.\n",
    "#ndb_col = food_info[\"NDB_No\"]\n",
    "#print ndb_col\n",
    "# Alternatively, you can access a column by passing in a string variable.\n",
    "#col_name = \"NDB_No\"\n",
    "#ndb_col = food_info[col_name]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#columns = [\"Zinc_(mg)\", \"Copper_(mg)\"]\n",
    "#zinc_copper = food_info[columns]\n",
    "#print zinc_copper\n",
    "#print zinc_copper\n",
    "# Skipping the assignment.\n",
    "#zinc_copper = food_info[[\"Zinc_(mg)\", \"Copper_(mg)\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "#print(food_info.columns)\n",
    "#print(food_info.head(2))\n",
    "col_names = food_info.columns.tolist()\n",
    "#print col_names\n",
    "gram_columns = []\n",
    "\n",
    "for c in col_names:\n",
    "    if c.endswith(\"(g)\"):\n",
    "        gram_columns.append(c)\n",
    "gram_df = food_info[gram_columns]\n",
    "print(gram_df.head(3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
